#include "stdafx.h"

#include "HiddenObject.h"
#include "Inventory.h"
#include "Dialogue.h"

int gCurrentHiddenObject = 0;
sf::SoundBuffer* HiddenObject::collectBuffer = 0;
sf::Sound* HiddenObject::collectSound = 0;

HiddenObject::HiddenObject(const char* filename, sf::Vector2f p, int id, std::vector<const char*> dialogue1Texts, std::vector<bool> dialogue1People)
{
	if (!collectBuffer)
	{
		collectBuffer = new sf::SoundBuffer();
		collectBuffer->loadFromFile("data/sounds/collect.wav");
		collectSound = new sf::Sound(*collectBuffer);
	}

	mDialogue1Texts = dialogue1Texts;
	mDialogue1People = dialogue1People;

	mTexture.loadFromFile(filename);
	mSprite.setTexture(mTexture);
	mSprite.setPosition(p);

	type = GOT_FEMALE_VISIBLE;

	mId = id;

	pos = p;
	size = sf::Vector2f(mTexture.getSize().x, mTexture.getSize().y);
	mSprite.setOrigin(size / 2.0f);
}

void HiddenObject::Draw(sf::RenderWindow& window)
{
	if(gCurrentHiddenObject == mId)
	{
		GameObject::Draw(window);
		mSprite.setScale(pulseScale);
		window.draw(mSprite);
	}
}

void HiddenObject::OnTouch(Player* player)
{
	if(gCurrentHiddenObject == mId)
	{
		gInventory.Add(mSprite);
		gCurrentHiddenObject++;

		activeDialogue.Load(mDialogue1Texts, mDialogue1People);

		collectSound->play();
	}
}